

const path = require('path');
const staticImg = path.join(__dirname, 'static');

function SensorbitUnoBlocks(Blockly) {
    var show_color = "#f59057";






    //  tm1650数码管初始化
    Blockly.Blocks.microbit_tm1650Init = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/37.4-digit  7-segment.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_TM1650)
            .appendField(new Blockly.FieldDropdown([
                ["0", "0"],
                ["1", "1"],
                ["2", "2"],
                ["3", "3"],
                ["4", "4"],
                ["5", "5"],
                ["6", "6"],
                ["7", "7"],
                [Blockly.Msg.MICROBIT_TM1650CLOSE, ""]
            ]), "tm1650Intensity");
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

  

     // tm1650数码管展示
     Blockly.Blocks.microbit_tm1650display = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/37.4-digit  7-segment.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_TM1650DISPLAY)
            .appendField(new Blockly.FieldDropdown([
             [Blockly.Msg.MICROBIT_TM1650FIRST, "0"],
             [Blockly.Msg.MICROBIT_TM1650SECOND, "1"],
             [Blockly.Msg.MICROBIT_TM1650THIRD, "2"],
             [Blockly.Msg.MICROBIT_TM1650FORTH, "3"],
            ]),"TM1650Bit");
            this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_TM1650DISPLAYDATA)
            this.appendValueInput("tm1650Data", Number)
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };


    // tm1650数码管展示小数点
    Blockly.Blocks.microbit_tm1650PointDisplay = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/37.4-digit  7-segment.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_TM1650POINTDISPLAY)
            .appendField(new Blockly.FieldDropdown([
             [Blockly.Msg.MICROBIT_TM1650FIRST, "0"],
             [Blockly.Msg.MICROBIT_TM1650SECOND, "1"],
             [Blockly.Msg.MICROBIT_TM1650THIRD, "2"],
             [Blockly.Msg.MICROBIT_TM1650FORTH, "3"],
            ]),"TM1650PointBit");
            this.appendDummyInput("")
            .appendField(Blockly.Msg.MICROBIT_LCDSHOW);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldDropdown([
                [Blockly.Msg.MICROBIT_TM1650OPEN, "True"],
                [Blockly.Msg.MICROBIT_TM1650CLOSE, "False"],
                ]),"tm1650Point")
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };



    // tm1650数码管显示数字  
    Blockly.Blocks.microbit_tm1650ShowNumber = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/37.4-digit  7-segment.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_TM1650SHOWNUMBER)
            this.appendValueInput("tm1650Number", Number)
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

    

    // tm1650数码管清屏
    Blockly.Blocks.microbit_tm1650Clear = {
        init:function(){
            this.setColour(show_color);
            this.appendDummyInput("")
            .appendField(new Blockly.FieldImage(staticImg+"/37.4-digit  7-segment.svg", 84, 42))
            .appendField(Blockly.Msg.MICROBIT_TM1650CLEAR);
            this.setPreviousStatement(true,null);
            this.setNextStatement(true,null);
            this.setTooltip('');
        }
    };

    return Blockly;
}

module.exports = SensorbitUnoBlocks;

